package com.coda.app.controller;

import com.coda.app.service.LoginService;
import com.coda.appVo.user.LoginVo;
import com.coda.appVo.user.UserInfoVo;
import com.coda.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/app")
@Api(tags = "登录管理")
public class LoginController {

    @Autowired
    private LoginService loginService;

    /**
     * 获取短信验证码
     * @param phone
     * @return
     */
    @GetMapping("/login/getCode")
    @ApiOperation("获取短信验证码")
    public Result getCode(@RequestParam String phone){
        loginService.getCode(phone);
        return Result.ok();
    }

    /**
     * 登录和注册
     */
    @PostMapping("/login")
    @ApiOperation("登录和注册")
    public Result<String> login(@RequestBody LoginVo loginVo){
        String token = loginService.login(loginVo);
        return Result.ok(token);
    }

    /**
     * 获取登录用户信息
     */
    @GetMapping("/info")
    @ApiOperation("获取登录用户信息")
    public Result<UserInfoVo> getUserInfo(){
        UserInfoVo userInfoVo = loginService.getUserInfo();
        return Result.ok(userInfoVo);
    }
}
